package cc.kzc.adminauth.auth;

import java.security.PrivateKey;
import java.security.PublicKey;

import cc.kzc.adminauth.auth.tool.AsymmJwtUtil;
import cc.kzc.adminauth.auth.tool.JwtKeyGenerator;
import io.jsonwebtoken.Claims;

public class JwtProcessor {

	private static final String PRIVATE_KEY_STRING = "MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCACVtAH3UZ+QZrVoY1E2Bg+m5Nbx6hhXi10AQD7wy0R5w==";
	private static final PrivateKey PRIVATE_KEY = JwtKeyGenerator.parsePrivateKeyFromBase64(PRIVATE_KEY_STRING,
			JwtKeyGenerator.KEY_ALGORITHM_EC);

	private static final String PUBLIC_KEY_STRING = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEmw3Yhb/9bBsVpIPvdRK+cg+PCFmTtfx3+hfjM0VKSD5kst6G4Dz/jMwld0q6HW0CkjwipHtrdtXqDXr2b08nZg==";
	private static final PublicKey PUBLIC_KEY = JwtKeyGenerator.parsePublicKeyFromBase64(PUBLIC_KEY_STRING,
			JwtKeyGenerator.KEY_ALGORITHM_EC);

	private static final long TIME_EXPIRE = 3600L * 24;

	public static String createJWT(String user) {
		return createJWT(user, TIME_EXPIRE);
	}

	public static String createJWT(String user, long expire) {

		String jwtToken = AsymmJwtUtil.genToken(PRIVATE_KEY, user, null, null, expire);
		return jwtToken;
	}
	
	public static Claims parseJWT(String token) {
		
		Claims claims = AsymmJwtUtil.parsePayload(PUBLIC_KEY, token);
		
		return claims;
	}

}
